import lazyLoad from "./lazyLoad.js";
import Paga from "./paga.js";
import Rendergood from "./rendergood.js";

export default class goodList {
    usermsg;
    id
    renderGood
    span
    start
    end
    next
    prev
    index
    pagination 
    constructor() {
        //用户名
        this.usermsg = JSON.parse(sessionStorage.getItem("usermsg"));
        this.username = document.getElementById("username");
        if (this.usermsg) this.writeUserMsg();
        this.data = null;
        this.myCar = document.getElementById("myCar")
        this.lis = document.querySelectorAll("lis")

        this.selectProList()

        new lazyLoad("goodList img")
      
    }
    writeUserMsg() {
        this.username.innerHTML = this.usermsg.username
        this.username.className = "login"
    }
    bindEvent() {
        this.myCar.addEventListener("click", e => this.carclickHandler(e));
    }

    carclickHandler(e) {
        if (this.usermsg) {
            this.goCar(this.id)
            this.id = this.usermsg.username
        }
        else {
            alert("未登录")
            location.href = "./signIn.html";
        }
    }
    goCar(id) {
        location.href = "./car.html#id=" + id;
    }
    selectProList() {
        fetch("http://localhost:4022/prolist").then(res => res.json())
            .then(
                res => {
                    
                   this.pagination = new Paga(res,{
                    show_num : 5
              })
              console.log(this.pagination);
              console.log(this.pagination.span);
                })

    }
    
  
    
   

}
new goodList()